package com.source.multithread.download;

/**
 * @Author wengqy
 * @Date 2020/12/25
 */
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class ThreadPoolTest {
    static int i=0;
    /**
     * @param args
     */
    // https://www.bilibili.com/video/av54393075  并发编程1-线程池框架(完整)
    //https://www.bilibili.com/video/av57461478/  6手把手写线程池
    // https://v.youku.com/v_show/id_XNDA4ODU4OTA0MA==.html?spm=a2h0j.11185381.listitem_page1.5!4~A
    public static void main(String[] args) {
        //ExecutorService threadPool = Executors.newFixedThreadPool(3);
        //ExecutorService threadPool = Executors.newCachedThreadPool();
        ExecutorService threadPool = Executors.newSingleThreadExecutor();
		/*for(int i=1;i<=10;i++){
			final int task = i;
			threadPool.execute(new Runnable(){
				@Override
				public void run() {
					for(int j=1;j<=10;j++){
						try {
							Thread.sleep(20);
						} catch (InterruptedException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						System.out.println(Thread.currentThread().getName() + " is looping of " + j + " for  task of " + task);
					}
				}
			});
		}
		System.out.println("all of 10 tasks have committed! ");*/
        //	threadPool.shutdownNow();

        Executors.newScheduledThreadPool(3).scheduleAtFixedRate(
                new Runnable(){
                    @Override
                    public void run() {
                        System.out.println("bombing!"+(i++));

                    }},
                10,
                5,
                TimeUnit.SECONDS);
    }

}

